<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>analyzer | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'analyzer.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/analyzer.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/analyzer.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/analyzer.html" rel="nofollow" target="_blank">../en/analyzer.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="mapping.html">Mapping</a></span>
»
<span class="breadcrumb-link"><a href="mapping-params.html">Mapping parameters</a></span>
»
<span class="breadcrumb-node"><code class="literal">analyzer</code></span>
</div>
<div class="navheader">
<span class="prev">
<a href="mapping-params.html">« Mapping parameters</a>
</span>
<span class="next">
<a href="mapping-boost.html"><code class="literal">boost</code> »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="analyzer"></a><code class="literal">analyzer</code><a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/mapping/params/analyzer.asciidoc">edit</a>
</h2>
</div></div></div>
<div class="important admon">
<div class="icon"></div>
<div class="admon_content">
<p>Only <a class="xref" href="text.html" title="Text datatype"><code class="literal">text</code></a> fields support the <code class="literal">analyzer</code> mapping parameter.</p>
</div>
</div>
<p>The <code class="literal">analyzer</code> parameter specifies the <a class="xref" href="analyzer-anatomy.html" title="Anatomy of an analyzer">analyzer</a> used for
<a class="xref" href="analysis.html" title="Text analysis">text analysis</a> when indexing or searching a <code class="literal">text</code> field.</p>
<p>Unless overridden with the <a class="xref" href="search-analyzer.html" title="search_analyzer"><code class="literal">search_analyzer</code></a> mapping
parameter, this analyzer is used for both <a class="xref" href="analysis-index-search-time.html" title="Index and search analysis">index and
search analysis</a>. See <a class="xref" href="specify-analyzer.html" title="Specify an analyzer">Specify an analyzer</a>.</p>
<div class="tip admon">
<div class="icon"></div>
<div class="admon_content">
<p>We recommend testing analyzers before using them in production. See
<a class="xref" href="test-analyzer.html" title="Test an analyzer">Test an analyzer</a>.</p>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="search-quote-analyzer"></a><code class="literal">search_quote_analyzer</code><a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/mapping/params/analyzer.asciidoc">edit</a>
</h3>
</div></div></div>
<p>The <code class="literal">search_quote_analyzer</code> setting allows you to specify an analyzer for phrases, this is particularly useful when dealing with disabling
stop words for phrase queries.</p>
<p>To disable stop words for phrases a field utilising three analyzer settings will be required:</p>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
An <code class="literal">analyzer</code> setting for indexing all terms including stop words
</li>
<li class="listitem">
A <code class="literal">search_analyzer</code> setting for non-phrase queries that will remove stop words
</li>
<li class="listitem">
A <code class="literal">search_quote_analyzer</code> setting for phrase queries that will not remove stop words
</li>
</ol>
</div>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT my_index
{
   "settings":{
      "analysis":{
         "analyzer":{
            "my_analyzer":{ <a id="CO332-1"></a><i class="conum" data-value="1"></i>
               "type":"custom",
               "tokenizer":"standard",
               "filter":[
                  "lowercase"
               ]
            },
            "my_stop_analyzer":{ <a id="CO332-2"></a><i class="conum" data-value="2"></i>
               "type":"custom",
               "tokenizer":"standard",
               "filter":[
                  "lowercase",
                  "english_stop"
               ]
            }
         },
         "filter":{
            "english_stop":{
               "type":"stop",
               "stopwords":"_english_"
            }
         }
      }
   },
   "mappings":{
       "properties":{
          "title": {
             "type":"text",
             "analyzer":"my_analyzer", <a id="CO332-3"></a><i class="conum" data-value="3"></i>
             "search_analyzer":"my_stop_analyzer", <a id="CO332-4"></a><i class="conum" data-value="4"></i>
             "search_quote_analyzer":"my_analyzer" <a id="CO332-5"></a><i class="conum" data-value="5"></i>
         }
      }
   }
}

PUT my_index/_doc/1
{
   "title":"The Quick Brown Fox"
}

PUT my_index/_doc/2
{
   "title":"A Quick Brown Fox"
}

GET my_index/_search
{
   "query":{
      "query_string":{
         "query":"\"the quick brown fox\"" <a id="CO332-6"></a><i class="conum" data-value="6"></i>
      }
   }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/742.console"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO332-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p><code class="literal">my_analyzer</code> analyzer which tokens all terms including stop words</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO332-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p><code class="literal">my_stop_analyzer</code> analyzer which removes stop words</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO332-3"><i class="conum" data-value="3"></i></a></p>
</td>
<td align="left" valign="top">
<p><code class="literal">analyzer</code> setting that points to the <code class="literal">my_analyzer</code> analyzer which will be used at index time</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO332-4"><i class="conum" data-value="4"></i></a></p>
</td>
<td align="left" valign="top">
<p><code class="literal">search_analyzer</code> setting that points to the <code class="literal">my_stop_analyzer</code> and removes stop words for non-phrase queries</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO332-5"><i class="conum" data-value="5"></i></a></p>
</td>
<td align="left" valign="top">
<p><code class="literal">search_quote_analyzer</code> setting that points to the <code class="literal">my_analyzer</code> analyzer and ensures that stop words are not removed from phrase queries</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO332-6"><i class="conum" data-value="6"></i></a></p>
</td>
<td align="left" valign="top">
<p>Since the query is wrapped in quotes it is detected as a phrase query therefore the <code class="literal">search_quote_analyzer</code> kicks in and ensures the stop words
are not removed from the query. The <code class="literal">my_analyzer</code> analyzer will then return the following tokens [<code class="literal">the</code>, <code class="literal">quick</code>, <code class="literal">brown</code>, <code class="literal">fox</code>] which will match one
of the documents. Meanwhile term queries will be analyzed with the <code class="literal">my_stop_analyzer</code> analyzer which will filter out stop words. So a search for either
<code class="literal">The quick brown fox</code> or <code class="literal">A quick brown fox</code> will return both documents since both documents contain the following tokens [<code class="literal">quick</code>, <code class="literal">brown</code>, <code class="literal">fox</code>].
Without the <code class="literal">search_quote_analyzer</code> it would not be possible to do exact matches for phrase queries as the stop words from phrase queries would be
removed resulting in both documents matching.</p>
</td>
</tr>
</table>
</div>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="mapping-params.html">« Mapping parameters</a>
</span>
<span class="next">
<a href="mapping-boost.html"><code class="literal">boost</code> »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>